package com.guang.springbootexception.web;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.guang.springbootexception.exceptionresolver.ExceptionControllerAdvice;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Iterator;
import java.util.List;

/**
 *
 * 为了全面结果SpringMVC，这里也是可以来进行设置的
 *  https://blog.csdn.net/qq_41071876/article/details/105607685?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-0-105607685-blog-94445071.pc_relevant_paycolumn_v3&spm=1001.2101.3001.4242.1&utm_relevant_index=3
 * @author liguang
 * @date 2022/5/19 10:13
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
        Iterator var2 = converters.iterator();

        while(var2.hasNext()) {
            HttpMessageConverter<?> converter = (HttpMessageConverter)var2.next();
            if (converter instanceof MappingJackson2HttpMessageConverter) {
                ObjectMapper objectMapper = ((MappingJackson2HttpMessageConverter)converter).getObjectMapper();
                objectMapper.configure(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN, true);
            }
        }

    }

//    /**
//     * 如果配置的是这个，那么将会导致所有的失效，而只使用这一个！
//     * @param resolvers
//     */
//    @Override
//    public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> resolvers) {
//        WebMvcConfigurer.super.configureHandlerExceptionResolvers(resolvers);
//    }
//
//    /**
//     * 这个是作为扩展的异常处理器！也就是说针对系统中的多个都可以来进行处理
//     * @param resolvers
//     */
//    @Override
//    public void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> resolvers) {
//        WebMvcConfigurer.super.extendHandlerExceptionResolvers(resolvers);
//    }
//
//
//
//    @Bean
//    public ExceptionControllerAdvice exceptionControllerAdvice() {
//        return new ExceptionControllerAdvice();
//    }
}
